|
|
@@ -51,6 +51,31 @@ describe Agents::ImapFolderAgent do
|
51
|
51
|
stub(@checker).each_unread_mail.returns { |yielder|
|
52
|
52
|
@mails.each(&yielder)
|
53
|
53
|
}
|
|
54
|
+
|
|
55
|
+ @payloads = [
|
|
56
|
+ {
|
|
57
|
+ 'from' => 'nanashi.gombeh@example.jp',
|
|
58
|
+ 'to' => ['jane.doe@example.com', 'john.doe@example.com'],
|
|
59
|
+ 'cc' => [],
|
|
60
|
+ 'date' => '2014-05-09T16:00:00+09:00',
|
|
61
|
+ 'subject' => 'some subject',
|
|
62
|
+ 'body' => "Some plain text\nSome second line\n",
|
|
63
|
+ 'has_attachment' => false,
|
|
64
|
+ 'matches' => {},
|
|
65
|
+ 'mime_type' => 'text/plain',
|
|
66
|
+ },
|
|
67
|
+ {
|
|
68
|
+ 'from' => 'john.doe@example.com',
|
|
69
|
+ 'to' => ['jane.doe@example.com', 'nanashi.gombeh@example.jp'],
|
|
70
|
+ 'cc' => [],
|
|
71
|
+ 'subject' => 'Re: some subject',
|
|
72
|
+ 'body' => "Some reply\n",
|
|
73
|
+ 'date' => '2014-05-09T17:00:00+09:00',
|
|
74
|
+ 'has_attachment' => true,
|
|
75
|
+ 'matches' => {},
|
|
76
|
+ 'mime_type' => 'text/plain',
|
|
77
|
+ }
|
|
78
|
+ ]
|
54
|
79
|
end
|
55
|
80
|
|
56
|
81
|
describe 'validations' do
|
|
|
@@ -83,29 +108,7 @@ describe Agents::ImapFolderAgent do
|
83
|
108
|
(seen[mail.uidvalidity] ||= []) << mail.uid
|
84
|
109
|
}
|
85
|
110
|
|
86
|
|
- events = Event.last(2)
|
87
|
|
- events.first.payload.should == {
|
88
|
|
- 'from' => 'nanashi.gombeh@example.jp',
|
89
|
|
- 'to' => ['jane.doe@example.com', 'john.doe@example.com'],
|
90
|
|
- 'cc' => [],
|
91
|
|
- 'date' => '2014-05-09T16:00:00+09:00',
|
92
|
|
- 'subject' => 'some subject',
|
93
|
|
- 'body' => "Some plain text\nSome second line\n",
|
94
|
|
- 'has_attachment' => false,
|
95
|
|
- 'matches' => {},
|
96
|
|
- 'mime_type' => 'text/plain',
|
97
|
|
- }
|
98
|
|
- events.last.payload.should == {
|
99
|
|
- 'from' => 'john.doe@example.com',
|
100
|
|
- 'to' => ['jane.doe@example.com', 'nanashi.gombeh@example.jp'],
|
101
|
|
- 'cc' => [],
|
102
|
|
- 'subject' => 'Re: some subject',
|
103
|
|
- 'body' => "Some reply\n",
|
104
|
|
- 'date' => '2014-05-09T17:00:00+09:00',
|
105
|
|
- 'has_attachment' => true,
|
106
|
|
- 'matches' => {},
|
107
|
|
- 'mime_type' => 'text/plain',
|
108
|
|
- }
|
|
111
|
+ Event.last(2).map(&:payload) == @payloads
|
109
|
112
|
|
110
|
113
|
lambda { @checker.check }.should_not change { Event.count }
|
111
|
114
|
end
|
|
|
@@ -119,17 +122,7 @@ describe Agents::ImapFolderAgent do
|
119
|
122
|
(seen[mail.uidvalidity] ||= []) << mail.uid
|
120
|
123
|
}
|
121
|
124
|
|
122
|
|
- Event.last.payload.should == {
|
123
|
|
- 'from' => 'nanashi.gombeh@example.jp',
|
124
|
|
- 'to' => ['jane.doe@example.com', 'john.doe@example.com'],
|
125
|
|
- 'cc' => [],
|
126
|
|
- 'date' => '2014-05-09T16:00:00+09:00',
|
127
|
|
- 'subject' => 'some subject',
|
128
|
|
- 'body' => "Some plain text\nSome second line\n",
|
129
|
|
- 'has_attachment' => false,
|
130
|
|
- 'matches' => {},
|
131
|
|
- 'mime_type' => 'text/plain',
|
132
|
|
- }
|
|
125
|
+ Event.last.payload.should == @payloads.first
|
133
|
126
|
|
134
|
127
|
lambda { @checker.check }.should_not change { Event.count }
|
135
|
128
|
end
|
|
|
@@ -146,17 +139,11 @@ describe Agents::ImapFolderAgent do
|
146
|
139
|
(seen[mail.uidvalidity] ||= []) << mail.uid
|
147
|
140
|
}
|
148
|
141
|
|
149
|
|
- Event.last.payload.should == {
|
150
|
|
- 'from' => 'john.doe@example.com',
|
151
|
|
- 'to' => ['jane.doe@example.com', 'nanashi.gombeh@example.jp'],
|
152
|
|
- 'cc' => [],
|
153
|
|
- 'subject' => 'Re: some subject',
|
|
142
|
+ Event.last.payload.should == @payloads.last.update(
|
154
|
143
|
'body' => "<div dir=\"ltr\">Some HTML reply<br></div>\n",
|
155
|
|
- 'date' => '2014-05-09T17:00:00+09:00',
|
156
|
|
- 'has_attachment' => true,
|
157
|
144
|
'matches' => { 'a' => 'some subject', 'b' => 'HTML' },
|
158
|
145
|
'mime_type' => 'text/html',
|
159
|
|
- }
|
|
146
|
+ )
|
160
|
147
|
|
161
|
148
|
lambda { @checker.check }.should_not change { Event.count }
|
162
|
149
|
end
|